<?php

class ContactController extends Core_Controller_Action 
{	
	public function init() {
		
	}
	
	public function indexAction() {
		$this->view->title = 'contact';
		if ($this->_request->isPost()) {
			
			$data = $this->_request->getPost();
			$validator = new Zend_Validate_EmailAddress();
			
			if( !$validator->isValid( $data['email'] ) ) {
	          $this->view->error = -3;
	          $this->view->data = $data;
       		}
       		else
       		{
       			if(!empty($data['title']) && !empty($data['content']))
       			{
       				$mail = new Core_Mail();
       				
       				$mail->addTo( "kontakt@cataklysm.pl", "Kontakt" );
       				$mail->setFrom( $data['email'] );
					$mail->setSubject( $data['title'] );
					$mail->setBodyText( strip_tags( $data['content'] ) );
					$mail->setBodyHtml( $data['content'] );
					
					$mail->send();
					Core_Logs::log( 'cataclysm', 'send_mail', 'wyslalem email do kontaktu z adresem: '.$data['email'] );
       				$this->_redirect("index");
       			}
       			else
       			{
       				$this->view->error = -3;
	          		$this->view->data = $data;
       			}
       		}
		}
	}
}
?>